  
<cfcomponent displayname="libAccessDAO" hint="I abstract data access for libAccess.">

	<cffunction name="init" access="public" returntype="libAccessDAO" output="false" displayname="libAccess Constructor" hint="I initialize a libAccess.">
		<cfargument name="datasourceSettings" type="any" required="true" />
		
		<cfset variables.dsn = arguments.datasourceSettings.getConfigSetting("dsn") />
		<cfset variables.dbtype = arguments.datasourceSettings.getConfigSetting("dbtype") />

		<cfreturn this />
	</cffunction>
 
	<cffunction name="save" returntype="any" output="false" access="public" 	hint="I save a libAccess">
		<cfargument name="libAccess" type="libAccess" hint="I am the libAccess to be saved" required="true"/>
		
		<cfreturn create(arguments.libAccess)/>
		
	</cffunction>

	<cffunction name="create" access="remote" returntype="any" output="false">
		<cfargument name="libAccessBean" type="libAccess" required="true" hint="I am the libAccess object into which data is created." />/>
		<cfset var insRec = false />
		<cfquery name="insRec" datasource="#variables.dsn#">
			insert into libAccess(
			userid, libid
			)
			values(
				<cfqueryparam cfsqltype="cf_sql_VARCHAR" value="#arguments.libAccessBean.getuserid()#"  /> 
				, <cfqueryparam cfsqltype="cf_sql_VARCHAR" value="#arguments.libAccessBean.getlibID()#"  /> 
				)
		</cfquery>
		
		<cfreturn arguments.libAccessBean/>
	</cffunction>
	
	<cffunction name="read" access="public" returntype="any" output="false" hint="CRUD method read.">
		<cfargument name="userid" type="string" required="true" hint="I am the ID of the database record to read." />
		<cfargument name="libID" type="string" required="true" hint="I am the ID of the database record to read." />
		<cfset var libAccessBean = createobject("component","libAccess").init() />
		<cfset var libAccessSelect = false />
		
		<cfquery name="libAccessSelect" datasource="#variables.dsn#">
			SELECT *  
			FROM	libAccess	
			WHERE
				userid = <cfqueryparam cfsqltype="cf_sql_VARCHAR" value="#arguments.userid#"  /> 
				AND libID = <cfqueryparam cfsqltype="cf_sql_VARCHAR" value="#arguments.libID#"  /> 
				
		</cfquery>

		<cfif libAccessSelect.recordCount >
			<cfscript>
				libAccessBean.setuserid(libAccessSelect.userid);				
				libAccessBean.setlibID(libAccessSelect.libID);				
				
			</cfscript>			
			
		</cfif>
		
		<cfreturn libAccessBean />
	</cffunction>

	<cffunction name="delete" returntype="void" output="false" hint="CRUD method delete" >
		<cfargument name="libAccessBean" type="libAccess" required="true" />		

		<cfset var libAccessDelete = 0 >

		<cfquery name="libAccessDelete" datasource="#variables.dsn#" >
			DELETE FROM libAccess
			WHERE
				userid = <cfqueryparam cfsqltype="cf_sql_VARCHAR" value="#arguments.libAccessBean.getuserid()#"  /> 
				AND libID = <cfqueryparam cfsqltype="cf_sql_VARCHAR" value="#arguments.libAccessBean.getlibID()#"  /> 
				
		</cfquery>
	</cffunction>

</cfcomponent>

  
